package br.com.financeiro.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;

import br.com.financeiro.dominio.Conta;

@Component
public class ContaDao extends HibernateDaoSupport{
	
	public ContaDao(){
		
	}
	
	@Autowired
	public ContaDao(SessionFactory sf){
		setSessionFactory(sf);
	}
	
	@SuppressWarnings("unchecked")
	public List<Conta> findByMesAno(int mes, int ano){
		String hql = "SELECT conta " +
				"FROM Conta conta " +
				"WHERE EXTRACT(MONTH FROM conta.dataVencimento) = ? " +
				"AND EXTRACT(YEAR FROM conta.dataVencimento) = ? " +
				"ORDER BY conta.dataVencimento ASC";
		
		return (ArrayList<Conta>)getHibernateTemplate().find(hql, mes, ano);
	}

}